import org.junit.Test;

import java.io.File;
import java.io.IOException;

public class FileListTest {
    public static void main(String[] args) {

    }

    @Test
    public void test1() {
        File file = new File("directoryTest");
        File[] files = file.listFiles();
        for(File f: files) {
            getDirectory(f);
        }
    }

    public void getDirectory(File file) {
        if (file.isDirectory()) {
            for (File f : file.listFiles()) {
                getDirectory(f);
            }
        } else {
            System.out.println(file);
        }
    }
    @Test
    public void test2() {
        File file = new File("directoryTest", "test");
        File[] files = file.listFiles();
        for (File f : files) {
            delDirectory(f);
        }
    }

    public void delDirectory(File file) {
        if (file.isDirectory()) {
            for (File f : file.listFiles()) {
                delDirectory(f);
            }
        } else {
            System.out.println(file.delete());
        }
    }
    @Test
    public void test3() {
        File file = new File("directoryTest", "1.txt");
        String absolutePath = file.getParentFile().getAbsolutePath();
        File newFile = new File(absolutePath + "/666.json");
    try {
        boolean result = newFile.createNewFile();
        System.out.println(result ? "创建成功" : "创建失败");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
}
